<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 工序数据控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\exception\LogicException;
use common\service\TaskClockService;
use common\validate\TaskClock;
use think\Request;

class TaskClockController extends VerifyController
{
    protected $taskClockService;

    public function __construct()
    {
        parent::__construct();
        $this->taskClockService = new TaskClockService();
    }

    /**
     * 创建任务提醒时钟
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function createTaskClock(Request $request)
    {
        try {
            $data = $request->param()['data'];
            $res = $this->taskClockService->createTaskClock($data, $request->getUserId());
            return json(success_response('', $res));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }


    /**
     * 关闭任务时钟
     * @param Request $request
     * @return \think\Response
     */
    public function closeTaskClock(Request $request)
    {
        $res = $this->taskClockService->closeTaskClock($request->param()['param']['filter']);
        return json(success_response('', $res));
    }

    /**
     * 查询任务时钟
     * @param Request $request
     * @return \think\Response
     */
    public function selectTaskClock(Request $request)
    {
        $res = $this->taskClockService->selectTaskClock($request->param()['param']['filter'], $request->getUserId());
        return json(success_response('', $res));
    }

    /**
     * 提醒时间列表
     * @param Request $request
     * @return \think\Response
     */
    public function selectTaskClockList(Request $request)
    {
        $res = $this->taskClockService->selectTaskClockList($request->param()['param'], $request->getUserId(), $request->getTenantId());
        return json(success_response('', $res));
    }

    /**
     * 删除闹钟
     * @param Request $request
     * @return \think\Response
     */
    public function deleteTaskClock(Request $request)
    {
        $res = $this->taskClockService->deleteTaskClock($request->param()['param']['filter']);
        return json(success_response('', $res));
    }

}
